<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同详细信息</title>
<jsp:include page="../inc.jsp" flush="false"></jsp:include>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorCrm/businessOpportunitiesSel.js"
        charset="utf-8"></script>
        <script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorCrm/contractsSel.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/paymentRecordsList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/paymentRecordsForm.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/billingRecordsList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/billingRecordsForm.js"
        charset="utf-8"></script>
<script type="text/javascript">
Ext.onReady(function () {
    Ext.QuickTips.init();
    createForm();
    form = Ext.create('form');
    form.getForm().load({
        url: getRootPath()+"/contractsController/info.action",
        method: "POST",
        params: {
            id: '<%=request.getParameter("contractsId")%>'
        },
        waitTitle:'提示',
        waitMsg:'正在处理您的请求,请稍候...',
        success:function(form,action){

            if(form.findField("startDate").getValue()!=null){
                form.findField('startDate').setValue( new Date(parseInt(action.result.data.startDate )).format('yyyy-MM-dd'));
                form.findField('endDate').setValue( new Date(parseInt(action.result.data.endDate)).format('yyyy-MM-dd'));
            }
            if(form.findField("customersSigningDate").getValue()!=null){
                form.findField('customersSigningDate').setValue( new Date(action.result.data.customersSigningDate).format('yyyy-MM-dd'));
            }
            if(form.findField("companySignatureDate").getValue()!=null){
                form.findField('companySignatureDate').setValue( new Date(action.result.data.companySignatureDate ).format('yyyy-MM-dd'));
            }
            form.findField("customersName").setValue(action.result.data.customers.company.toString());
            form.findField("customersId").setValue(action.result.data.customers.id.toString());
            createLayout();
        }

    });
});

var  form, tabPanel;
// 创建form表单
function createForm() {
    Ext.define('form', {
        extend : 'Ext.form.Panel',
        fields : new Ext.util.MixedCollection(),
        initComponent : function() {
            this.items=[
                {xtype: 'hidden',
                    name: 'id',
                    dataIndex: 'id'
                },
                {xtype: 'hidden',
                    name: 'deleteFlag',
                    dataIndex: 'deleteFlag'
                },

                {
                    xtype: 'fieldset',
                    title: '客户信息',
                    collapsible: true,
                    defaults: {
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [{
                            xtype: 'textfield',
                            name: 'number',
                            dataIndex: 'number',
                            fieldLabel: '合同编号',
                            allowBlank: false
                        },
                            {
                                xtype: 'textfield',
                                name: 'name',
                                dataIndex: 'name',
                                fieldLabel: '合同名称',
                                allowBlank: false
                            }]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [  new dateTime({
                            name: 'startDate',
                            dataIndex: 'startDate',
                            format: 'Y-m-d',
                            fieldLabel: '生效日期',
                            allowBlank: false
                        }),
                            new dateTime({
                                name: 'endDate',
                                dataIndex: 'endDate',
                                format: 'Y-m-d',
                                fieldLabel: '到期日期',
                                allowBlank: false
                            })]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [ {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            items: [ {
                                xtype: 'hidden',
                                name: 'customersId',
                                dataIndex: 'customersId'
                            },{xtype:'textfield',
                                name: 'customersName',
                                dataIndex: 'customersName',
                                fieldLabel: '客户名称',
                                readOnly:true,
                                emailText:'请选择客户',
                                width: 230,
                                allowBlank: false
                            }]},
                            {
                                xtype: 'container',
                                layout: 'hbox',
                                margin: '0 0 5 0',
                                defaults: {
                                }, items: [ {xtype:'hidden',
                                name: 'businessOpportunitiesId',
                                dataIndex: 'businessOpportunitiesId'
                            },{xtype:'textfield',
                                name: 'businessOpportunitiesName',
                                dataIndex: 'businessOpportunitiesName',
                                fieldLabel: '业务机会',
                                readOnly:true,
                                emailText:'请选择业务机会',
                                width: 230,
                                allowBlank: false
                            },{
                                xtype:'button',
                                name: 'btnBusinessOpportunitiesId',
                                dataIndex: 'btnBusinessOpportunitiesId',
                                iconCls: 'searchIcon',
                                scope: this,
                                handler:this.onBusinessOpportunitiesSel,
                                width: 25
                            }]}]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [ {xtype:'numberfield',
                            name: 'contractAmount',
                            dataIndex: 'contractAmount',
                            allowDecimals: true,
                            decimalPrecision: 2,
                            mainValue:0,
                            fieldLabel: '合同金额',
                            allowBlank: true
                        }, new comboBox({
                            name: 'status',
                            dataIndex: 'status',
                            fieldLabel: '状态',
                            labelAlign: 'right',
                            codeName: '合同状态',
                            queryMode: 'local',
                            typeAhead: false,
                            forceSelection: true,
                            loadingText: '正在搜索...',
                            allowBlank: false,
                            hideTrigger: false
                        })]}
                    ]},
                {
                    xtype: 'fieldset',
                    title: '地址信息',
                    collapsible: true,
                    defaults: {
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [  {xtype:'textfield',
                        name: 'billingZipCode',
                        dataIndex: 'billingZipCode',
                        fieldLabel: '开单邮编',
                        allowBlank: true
                    },
                        {xtype:'textfield',
                            name: 'billingAddress',
                            dataIndex: 'billingAddress',
                            fieldLabel: '开单地址',
                            allowBlank: true
                        }, {xtype:'textfield',
                            name: 'shipZipCode',
                            dataIndex: 'shipZipCode',
                            fieldLabel: '发货邮编',
                            allowBlank: true
                        }, {xtype:'textfield',
                            name: 'shipAddress',
                            dataIndex: 'shipAddress',
                            fieldLabel: '发货地址',
                            allowBlank: true
                        }]},
                {
                    xtype: 'fieldset',
                    title: '备注信息',
                    collapsible: true,
                    defaults: {
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [ {xtype:'textarea',
                        name: 'specialItem',
                        dataIndex: 'specialItem',
                        fieldLabel: '特殊条款',
                        allowBlank: true
                    },  {xtype:'textarea',
                        name: 'remark',
                        dataIndex: 'remark',
                        fieldLabel: '备注',
                        allowBlank: true
                    }]},
                {
                    xtype: 'fieldset',
                    title: '签名信息',
                    collapsible: true,
                    defaults: {
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [ {xtype:'textfield',
                            name: 'customerSignatory',
                            dataIndex: 'customerSignatory',
                            fieldLabel: '客户签字人',
                            allowBlank: true
                        }   , {xtype:'textfield',
                            name: 'customerSignatoryDuties',
                            dataIndex: 'customerSignatoryDuties',
                            fieldLabel: '签字人职务',
                            allowBlank: true
                        }]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {

                            }, items: [ new dateTime({
                            name: 'customersSigningDate',
                            dataIndex: 'customersSigningDate',
                            format: 'Y-m-d',
                            fieldLabel: '客户签约日期',
                            allowBlank: true
                        })]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1
                            }, items: [ {xtype:'textfield',
                            name: 'companySignatory',
                            dataIndex: 'companySignatory',
                            fieldLabel: '公司签字人',
                            allowBlank: true
                        }, new dateTime({
                            name: 'companySignatureDate',
                            dataIndex: 'companySignatureDate',
                            format: 'Y-m-d',
                            fieldLabel: '公司签字日期',
                            allowBlank: true
                        })]}
                    ]}
            ];
            this.xtype= 'form';
            this.frame = false;
            this.border = true;
            this.split = true;
            this.autoScroll=true,
                    this.bodyPadding= 10,
                    this.bodyBorder= true;
            this.fieldDefaults= {
                labelWidth: 80,
                labelAlign:'right',
                msgTarget: 'side'
            };
            this.defaults={
                anchor: '100%'
            };
            this.callParent(arguments);
        },
        onRender : function() {
            this.callParent(arguments);
        }
    });
}

// 创建layout
function createLayout() {
    tabPanel= Ext.create('Ext.tab.Panel', {
        activeTab: 0,                       //指定默认的活动tab
        plain: true,                        //True表示tab候选栏上没有背景图片（默认为false）
        enableTabScroll: true,              //选项卡过多时，允许滚动
        defaults: { autoScroll: true },
        layout: 'fit',
        listeners:{
            tabchange:function(tp,p){

            }
        } ,
        items: [{
            title: '详细信息',
            items:[form],
            closable: false                  //这个tab可以被关闭
        },{
            layout: 'fit',
            title: '计划的活动',
            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="programActivities.jsp?entityID=<%=request.getParameter("contractsId")%>"></iframe>'
        },{
            layout: 'fit',
            title: '回款记录',
            items:[Ext.create('App.crm.paymentRecordsList')]
        },{
            layout: 'fit',
            title: '开票记录',
            items:[Ext.create('App.crm.billingRecordsList')]
        }  , {
            title: '附件',
            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="${pageContext.request.contextPath}/upload/attachment.jsp?businessKey=<%=request.getParameter("contractsId")%>"></iframe>'
        }]
    });
    var viewport = new Ext.Viewport({
        layout: 'fit',
        region: 'center',
        border: false,
        items: [
            tabPanel
        ]
    });
    viewport.doLayout();
}
</script>
</head>
<body>
</body>
</html>